package com.dao;

import com.entity.book;
import com.entity.reader;
import com.entity.search;
import com.utils.PropertiesUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class bookDao {
    public List<book> find(String bookname, String author_name) throws SQLException {
        QueryRunner queryRunner = new QueryRunner(PropertiesUtils.getDataSource());
        String sql = "select * from book where bookname = ? and author_name = ? ";
        List<book> list = queryRunner.query(sql, new BeanListHandler<>(book.class),bookname,author_name);
        return list;
    }
    public void add(book book) throws SQLException {
        QueryRunner queryRunner = new QueryRunner(PropertiesUtils.getDataSource());
        String sql = "insert into book(bookname,author_name,chapter_name,chapter_no,address) values(?,?,?,?,?)";
        queryRunner.update(sql,book.getBookname(),book.getAuthor_name(),book.getChapter_name(),book.getChapter_no(),book.getAddress());
    }
}
